package com.kevinwu.springboot.controller;

import com.kevinwu.springboot.pojo.Article;
import com.kevinwu.springboot.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 文章Controller
 */
@Controller
public class ArticleController {

    @Autowired
    IArticleService articleService;

    /**
     * 分页查询文章
     * @param modelMap
     * @param page
     * @param size
     * @return
     */
    @RequestMapping("/finAllArticle")
    public String finAllArticle(ModelMap modelMap, Integer page, Integer size){
        Pageable pageable = PageRequest.of(page, size);
        Page<Article> datas = articleService.findAllArticle(pageable);
        modelMap.addAttribute("datas", datas);
        return "client/index";
    }

}
